import { ConfigService } from '@ibiz-template/runtime';
import { ISearchBar } from '@ibiz/model-core';
import { IFilter } from './ehr-search-bar.state';

/**
 * 搜索栏服务
 *
 * @export
 * @class EhrSearchBarService
 */
export class EhrSearchBarService {
  /**
   * 应用配置服务
   *
   * @type {ConfigService}
   */
  private config: ConfigService;

  /**
   * Creates an instance of EhrSearchBarService.
   * @param {ISearchBar} model
   * @param {IContext} context
   * @memberof EhrSearchBarService
   */
  constructor(
    private readonly model: ISearchBar,
    private context: IContext,
  ) {
    this.config = new ConfigService(
      model.appId,
      'ehrsearchbar',
      `${context.srfuserid}_${this.model.appDataEntityId?.toLowerCase() || 'app'}_${this.model.codeName?.toLowerCase()}`,
    );
  }

  /**
   * @description 保存
   * @param {{ filters: IFilter[] }} data
   * @returns {*}  {Promise<void>}
   * @memberof EhrSearchBarService
   */
  async save(data: { filters: IFilter[] }): Promise<void> {
    await this.config.save(data);
  }

  /**
   * @description 加载
   * @returns {*}  {Promise<IData>}
   * @memberof EhrSearchBarService
   */
  async load(): Promise<IData> {
    return this.config.load();
  }
}
